var express = require("express");
var router = express.Router();
var { ListModel, xxinModel } = require("../model/model");

// 添加数据
router.get("/add", async (req, res) => {
  console.log(req.body);
  const data = await ListModel.create(req.body);
  res.send(data);
});

router.get("/list", async (req, res) => {
  const data = await ListModel.find();
  res.send(data);
});

router.get("/lists", async (req, res) => {
  let id = req.query.id;
  console.log(id);
  const data = await ListModel.find({_id:id});
  res.send(data);
});

// 用户信息表
router.get('/getxxin', async(req, res)=>{
  let list = []
  let fv = []
  let user = []
  let data = await xxinModel.find()
  data.forEach(item => {
    if(item.juese == 'qunid'){
      list.push(item)
    }
  })
  user = await ListModel.find()
  list.forEach(item => {
    user.forEach(item2 => {
      if(String(item.userid) == String(item2._id)){
        fv.push(item2)
      }
    })
  })
  res.send({fv})
})


module.exports = router;
